package com.pearadmin.pro.modules.training.controller;

import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.aop.annotation.Repeat;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.context.UserContext;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.modules.sys.domain.SysConfig;
import com.pearadmin.pro.modules.sys.param.SysConfigRequest;
import com.pearadmin.pro.modules.training.entity.LaboratoryInfo;
import com.pearadmin.pro.modules.training.entity.vo.PageLaboratoryInfoVO;
import com.pearadmin.pro.modules.training.service.LaboratoryInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Api(tags = {"实训室基本信息"})
@RestController
@RequestMapping(ControllerConstant.PREFIX_SYS + "lic")
public class LaboratoryInfoController extends BaseController {

    @Resource
    private LaboratoryInfoService laboratoryInfoService;
    @Resource
    private UserContext userContext;

    /**
     * 查询实训室列表
     *
     * @param request 查询参数
     * @return {@link Result}
     */
    @GetMapping("page")
    @Log(title = "实训室基本信息列表")
    @ApiOperation(value = "实训室基本信息列表")
    public Result page(PageLaboratoryInfoVO request){
        return success(laboratoryInfoService.page(request));
    }

    /**
     * 查询实训室列表
     *
     * @return {@link Result}
     */
    @GetMapping("infoList")
    @Log(title = "实训室基本信息列表")
    @ApiOperation(value = "实训室基本信息列表")
    public Result infoList(){
        return success(laboratoryInfoService.list());
    }
    /**
     * 新增实训室
     *
     * @param laboratoryInfo
     */
    @Repeat
    @PostMapping("save")
    @Log(title = "新增实训室")
    @ApiOperation(value = "新增实训室")
    public Result save(@RequestBody LaboratoryInfo laboratoryInfo) {
        laboratoryInfo.setCreateName(userContext.getUserId());
        laboratoryInfo.setCreateTime(LocalDateTime.now());
        return auto(laboratoryInfoService.save(laboratoryInfo));
    }
    @Repeat
    @PostMapping("Update")
    @Log(title = "修改实训室")
    @ApiOperation(value = "修改实训室")
    public Result Update(@RequestBody LaboratoryInfo laboratoryInfo) {
        laboratoryInfo.setUpdateName(userContext.getUserId());
        laboratoryInfo.setUpdateTime(LocalDateTime.now());
        return auto(laboratoryInfoService.updateById(laboratoryInfo));
    }
    /**
     * 删除实训室
     *
     * @param id 实训室编号
     */
    @DeleteMapping("remove")
    @Log(title = "删除实训室")
    @ApiOperation(value = "删除实训室")
    public Result remove(@RequestParam String id){
        return auto(laboratoryInfoService.removeById(id));
    }

    /**
     * 删除实训室
     *
     * @param ids 实训室编号
     * */
    @DeleteMapping("removeBatch")
    @Log(title = "删除实训室")
    @ApiOperation(value = "删除实训室")
    public Result removeBatch(@RequestParam List<String> ids) { return auto(laboratoryInfoService.removeByIds(ids)); }


}
